//
//  UIButton+LFTMCBlock.m
//  Pods
//
//  Created by Thomas Quan on 2017/5/8.
//
//

#import "UIButton+LFTMCBlock.h"
#import <objc/runtime.h>

@implementation UIButton (LFTMCBlock)

static char ActionTag;

- (void)addAction:(ButtonBlock)block forControlEvents:(UIControlEvents)controlEvents {
    objc_setAssociatedObject(self, &ActionTag, block, OBJC_ASSOCIATION_COPY_NONATOMIC);
    [self addTarget:self action:@selector(action:) forControlEvents:controlEvents];
}

- (void)action:(id)sender {
    ButtonBlock blockAction = (ButtonBlock)objc_getAssociatedObject(self, &ActionTag);
    if (blockAction) {
        blockAction(self);
    }
}

@end
